<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Contact_usual_holiday extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    public function index($sequence = "") {
        $html = $this->init("基礎資料-平常/假日聯絡", "jquery,pagination,base_data", "table");
        $this->load->model('contact_usual_holiday_model');
        $keyword = "";
        $config['per_page'] = 10;
        $config['total_rows'] = $this->contact_usual_holiday_model->get_all_count();
        $config['url'] = '/contact_usual_holiday/page_ajax';
        $config['num_pages'] = ceil($config['total_rows'] / $config['per_page']);
        $limit = $config['per_page'] . ",0";
        $html['page'] = $config;
        $html['sequence'] = $sequence;
        $html["contact_usual_holiday"] = $this->contact_usual_holiday_model->query_keyword($keyword, $limit);
        $this->load->view('contact_usual_holiday', $html);
    }

    public function page_ajax() {
        $this->load->model('contact_usual_holiday_model');
        $page = $this->input->post('page');
        $sequence = $this->input->post('sequence');
        $keyword = "";
        $html["edit_mode"] = "";
        $config['per_page'] = 10;
        $p = $config['per_page'] * ($page - 1);
        $limit = $config['per_page'] . "," . $p;
        $html["result"] = $this->contact_usual_holiday_model->query_keyword($keyword, $limit);
        $this->load->view('contact_usual_holiday_ajax', $html);
    }

    public function add() {
        $this->load->model('contact_usual_holiday_model');
        $data['value'] = $this->input->post('value');
        $data['explanation'] = $this->input->post('explanation');
        $data['sequence'] = $this->input->post('sequence');
        $return_result = $this->contact_usual_holiday_model->add($data);
        if ($return_result > 0) {
            redirect("/contact_usual_holiday");
        } else {
            echo "插入失敗";
        }
    }

    public function edit_ajax() {
        $this->load->model('contact_usual_holiday_model');
        $id = $this->input->post('contact_usual_holiday_id');
        $html["edit_mode"] = "edit";
        $html["info"] = $this->contact_usual_holiday_model->get_info($id);
        $this->load->view('contact_usual_holiday_ajax', $html);
    }

    public function edit_submit_ajax() {
        $this->load->model('contact_usual_holiday_model');
        $data['id'] = $this->input->post('contact_usual_holiday_id');
        $data['value'] = $this->input->post('value');
        $data['explanation'] = $this->input->post('explanation');
        $data['sequence'] = $this->input->post('sequence');
        $data['mtime'] = time();
        $return_result = $this->contact_usual_holiday_model->update_data($data);
        if ($return_result) {
            $html["edit_mode"] = "edit_return";
            $html["info"] = $this->contact_usual_holiday_model->get_info($data['id']);
            $this->load->view('contact_usual_holiday_ajax', $html);
        } else {
            echo "0";
        }
    }

    public function cancel_edit_ajax() {
        $this->load->model('contact_usual_holiday_model');
        $id = $this->input->post('contact_usual_holiday_id');
        $html["edit_mode"] = "edit_return";
        $html["info"] = $this->contact_usual_holiday_model->get_info($id);
        $this->load->view('contact_usual_holiday_ajax', $html);
    }

    public function data_delete($id = null) {
        $this->load->model('contact_usual_holiday_model');
        if ($id != null) {
            $data["id"] = $id;
            $return_result = $this->contact_usual_holiday_model->del($data);
            if ($return_result) {
                redirect("/contact_usual_holiday");
            } else {
                echo "刪除失敗";
            }
        } else {
            echo "刪除失敗";
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */